package com.base.myproject.client.busi;

import com.base.myproject.client.busi.BO.TreeNodeModelData;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

public class BaseStoreEvent extends GwtEvent {
	 private EventType eventType;
	 private int currowindex;
	 BaseStore basestore=null;
	 String cellname = null;
	 BaseTreeStore basetreestore =null;
	public int getCurrowindex() {
		return currowindex;
	}
	public void setCurrowindex(int currowindex) {
		this.currowindex = currowindex;
	}
	


	public BaseStore getBasestore() {
		return basestore;
	}
	public void setBasestore(BaseStore basestore) {
		this.basestore = basestore;
	}
	public BaseStoreEvent(Object arg0) {
		super();
		
	}

    private BaseStoreEvent(BaseStore source, EventType what ) {
        this(source);
        this.setBasestore(source);
        eventType = what;
    }

	public enum EventType {
		LOAD_STARTED,
		LOAD_COMPLETE,
		SAVE_STARTED,
		SAVE_COMPLETE,
		TABLE_CLEARED,
		ROW_CHANGED,//�з���ı�
		ROW_ADDED,
		ROW_DELETED,
		ROW_DISCARDED,
		CELL_CHANGED

	};

public EventType getEventType() {
		return eventType;
	}
	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}
	//	public static BaseStoreEvent newLoadStartEvent(Object source) {
//		return new BaseStoreEvent(source, EventType.LOAD_STARTED);
//	}
	/**
	 * 开始读取数据
	 */
	public static BaseStoreEvent BaseStoreLOAD_STARTED(BaseStore source) {
		return new BaseStoreEvent(source, EventType.LOAD_STARTED);
	}
	/**
	 * 读取数据完毕
	 * @param source
	 * @param eventtype
	 * @return
	 */
	public static BaseStoreEvent BaseStoreLoadComplete(BaseStore source) {
		return new BaseStoreEvent(source, EventType.LOAD_COMPLETE);
	}
	
	public static BaseStoreEvent BaseStoreRowAdded(BaseStore source) {
		return new BaseStoreEvent(source, EventType.ROW_ADDED);
	}
	/**
	 * 字段的值发生改变的时候出发。通常个情况下为了方便 BaseFormPanel 能够及时
	 * 获得改变的值，因此在BaseFormPanel捕捉事件。
	 * @param source
	 * @param cellname
	 * @return
	 */
	
	public static BaseStoreEvent BaseStoreCellChanged(BaseStore source,int index,String cellname) {
	
		BaseStoreEvent bse = new BaseStoreEvent(source, EventType.CELL_CHANGED);
		bse.setCurrowindex(index);
		bse.setCellname(cellname);
		return bse;
	}
	/**
	 * 准备保存数据
	 * @param source
	 * @return
	 */
	public static BaseStoreEvent BaseStoreSaveStart(BaseStore source) {
		return new BaseStoreEvent(source, EventType.SAVE_STARTED);
	}
	/**
	 * 保存数据完成
	 * @param source
	 * @return
	 */
	public static BaseStoreEvent BaseStoreSaveComplete(BaseStore source) {
		return new BaseStoreEvent(source, EventType.SAVE_COMPLETE);
	}
	/**
	 * �з���仯���¼�
	 * @param source
	 * @param torowindex
	 * @param eventtype
	 * @return
	 */
	public static BaseStoreEvent BaseStoreRowChangedEvent(BaseStore source,int torowindex) {
		BaseStoreEvent bse = new BaseStoreEvent(source, EventType.ROW_CHANGED);
		bse.setCurrowindex(torowindex);
		return bse;
	}
	@Override
	protected void dispatch(EventHandler handler) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Type getAssociatedType() {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * 字段的名字，字段改变的时候有用
	 * @return
	 */
	public String getCellname() {
		return cellname;
	}
	public void setCellname(String cellname) {
		this.cellname = cellname;
	}
	public BaseTreeStore getBasetreestore() {
		return basetreestore;
	}
	public void setBasetreestore(BaseTreeStore basetreestore) {
		this.basetreestore = basetreestore;
	}

}
